package com.yanqu.road.server.pb;

import com.yanqu.road.entity.activity.jieshi.*;
import com.yanqu.road.entity.activity.jieshi.config.*;
import com.yanqu.road.pb.activity.JieShiProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.ServerLanguageMgr;

import java.util.ArrayList;
import java.util.List;

public class JieShiPb {

    /**
     * 用户数据
     */
    public static JieShiProto.JieShiUserDataTemp.Builder parseUserDataTemp(JieShiUserData userData) {
        if (userData == null) {
            return null;
        }
        JieShiProto.JieShiUserDataTemp.Builder builder = JieShiProto.JieShiUserDataTemp.newBuilder();
        builder.setActivityId(userData.getActivityId());
        builder.setJieShiLevel(userData.getJieShiLevel());
        builder.setHour(userData.getHour());
        builder.setDollId(userData.getDollId());
        // 拥有的人偶列表
        for (JieShiDollData dollData : userData.getDollList()) {
            JieShiProto.JieShiDollDataTemp.Builder dollDataTemp = parseDollDataTemp(dollData);
            if (dollDataTemp != null) {
                builder.addDollList(dollDataTemp);
            }
        }
        // buff列表
        for (JieShiBuffData buffData : userData.getBuffList()) {
            JieShiProto.JieShiBuffDataTemp.Builder buffDataTemp = parseBuffDataTemp(buffData);
            if (buffDataTemp != null) {
                builder.addBuffList(buffDataTemp);
            }
        }
        builder.setEnergy(userData.getEnergy());
        builder.setLastEnergyRecTime(userData.getLastEnergyRecTime());
        builder.setMapId(userData.getMapId());
        // 地图上的建筑
        for (JieShiMapBuildData mapBuildData : userData.getMapBuildList()) {
            JieShiProto.JieShiMapBuildDataTemp.Builder mapBuildDataTemp = parseMapBuildDataTemp(mapBuildData);
            if (mapBuildDataTemp != null) {
                builder.addMapBuildList(mapBuildDataTemp);
            }
        }
        builder.addAllUnlockPosition(userData.getUnlockPosition());
        // 地图上的泼皮列表
        for (JieShiRuffianData ruffianData : userData.getRuffianList()) {
            JieShiProto.JieShiRuffianDataTemp.Builder ruffianDataTemp = parseRuffianDataTemp(ruffianData);
            if (ruffianDataTemp != null) {
                builder.addRuffianList(ruffianDataTemp);
            }
        }
        // 地图上的事件列表
        for (JieShiEventData eventData : userData.getEventList()) {
            JieShiProto.JieShiEventDataTemp.Builder eventDataTemp = parseEventDataTemp(eventData);
            if (eventDataTemp != null) {
                builder.addEventList(eventDataTemp);
            }
        }
        builder.setAttack(userData.getAttack());
        builder.setJiaoZi(userData.getJiaoZi());
        builder.setScore(userData.getScore());
        builder.setJieDaoSiLevel(userData.getJieDaoSiLevel());
        // 已拥有的活动门客数据
        for (JieShiPatronsData patron : userData.getPatronsDataList()) {
            JieShiProto.JieShiPatronsDataTemp.Builder patronsDataTemp = parsePatronsDataTemp(patron);
            if (patronsDataTemp != null) {
                builder.addPatrons(patronsDataTemp);
            }
        }
        builder.setRound(userData.getTravelTimes());
        builder.setGuide(userData.isGuide());
        builder.setNickName(userData.getNickName());
        builder.setChangeNameTimes(userData.getChangeNameTimes());
        return builder;
    }

    /**
     * 人偶
     */
    public static JieShiProto.JieShiDollDataTemp.Builder parseDollDataTemp(JieShiDollData dollData) {
        if (dollData == null) {
            return null;
        }
        JieShiProto.JieShiDollDataTemp.Builder builder = JieShiProto.JieShiDollDataTemp.newBuilder();
        builder.setDollId(dollData.getDollId());
        builder.setExpireTime(dollData.getExpireTime());
        return builder;
    }

    /**
     * buff
     */
    public static JieShiProto.JieShiBuffDataTemp.Builder parseBuffDataTemp(JieShiBuffData buffData) {
        if (buffData == null) {
            return null;
        }
        JieShiProto.JieShiBuffDataTemp.Builder builder = JieShiProto.JieShiBuffDataTemp.newBuilder();
        builder.setBuffId(buffData.getBuffId());
        builder.setStartRound(buffData.getStartRound());
        builder.setEffectRound(buffData.getEffectRound());
        return builder;
    }

    /**
     * 地图上的建筑
     */
    public static JieShiProto.JieShiMapBuildDataTemp.Builder parseMapBuildDataTemp(JieShiMapBuildData mapBuildData) {
        if (mapBuildData == null) {
            return null;
        }
        JieShiProto.JieShiMapBuildDataTemp.Builder builder = JieShiProto.JieShiMapBuildDataTemp.newBuilder();
        builder.setBuildId(mapBuildData.getBuildId());
        builder.addAllPosition(mapBuildData.getPosition());
        builder.setDirection(mapBuildData.getDirection());
        return builder;
    }

    /**
     * 泼皮事件
     */
    public static JieShiProto.JieShiRuffianDataTemp.Builder parseRuffianDataTemp(JieShiRuffianData ruffianData) {
        if (ruffianData == null) {
            return null;
        }
        JieShiProto.JieShiRuffianDataTemp.Builder builder = JieShiProto.JieShiRuffianDataTemp.newBuilder();
        builder.setEventId(ruffianData.getEventId());
        builder.setPosition(ruffianData.getPosition());
        builder.setAttack(ruffianData.getAttack());
        builder.setJiaoZi(ruffianData.getJiaoZi());
        builder.setGenRound(ruffianData.getGenRound());
        builder.setImageId(ruffianData.getImageId());
        return builder;
    }



    /**
     * 事件
     */
    public static JieShiProto.JieShiEventDataTemp.Builder parseEventDataTemp(JieShiEventData eventData) {
        if (eventData == null) {
            return null;
        }
        JieShiProto.JieShiEventDataTemp.Builder builder = JieShiProto.JieShiEventDataTemp.newBuilder();
        builder.setEventId(eventData.getEventId());
        builder.setPosition(eventData.getPosition());
        builder.setGenRound(eventData.getGenRound());
        return builder;
    }

    /**
     * 门客
     */
    public static JieShiProto.JieShiPatronsDataTemp.Builder parsePatronsDataTemp(JieShiPatronsData patronsData) {
        if (patronsData == null) {
            return null;
        }
        if (patronsData.getPatronsId() == 0) {
            return null;
        }
        JieShiProto.JieShiPatronsDataTemp.Builder builder = JieShiProto.JieShiPatronsDataTemp.newBuilder();
        builder.setPatronsId(patronsData.getPatronsId());
        builder.setAttack(patronsData.getAttack());
        return builder;
    }

    /**
     * 街市等级配置
     */
    public static JieShiProto.LightMarketMainLvConfig.Builder parseLightMarketMainLvConfig(LightMarketMainLvConfig mainLvConfig) {
        if (mainLvConfig == null) {
            return null;
        }
        JieShiProto.LightMarketMainLvConfig.Builder builder = JieShiProto.LightMarketMainLvConfig.newBuilder();
        builder.setLevel(mainLvConfig.getLevel());
        builder.setUpCost(mainLvConfig.getUpCost());
        builder.setBuildMaxNum(mainLvConfig.getBuildMaxNum());
        builder.setBuildTypeMaxNum(mainLvConfig.getBuildTypeMaxNum());
        return builder;
    }

    /**
     * 商铺表
     */
    public static JieShiProto.LightMarketShopConfig.Builder parseLightMarketShopConfig(LightMarketShopConfig shopConfig) {
        if (shopConfig == null) {
            return null;
        }
        JieShiProto.LightMarketShopConfig.Builder builder = JieShiProto.LightMarketShopConfig.newBuilder();
        builder.setId(shopConfig.getId());
        builder.setType(shopConfig.getType());
        builder.setArea(shopConfig.getArea());
        builder.setMoney(shopConfig.getMoney());
        builder.setFood(shopConfig.getFood());
        builder.setForce(shopConfig.getForce());
        builder.setEffectType(shopConfig.getEffectType());
        builder.setEffect(shopConfig.getEffect());
        return builder;
    }

    /**
     * 街道司
     */
    public static JieShiProto.LightMarketPatronConfig.Builder parseLightMarketPatronConfig(LightMarketPatronConfig patronConfig) {
        if (patronConfig == null) {
            return null;
        }
        JieShiProto.LightMarketPatronConfig.Builder builder = JieShiProto.LightMarketPatronConfig.newBuilder();
        builder.setLevel(patronConfig.getLevel());
        builder.setCost(patronConfig.getCost());
        builder.setEffect1(patronConfig.getEffect1());
        builder.setEffect2(patronConfig.getEffect2());
        builder.setPartonNum(patronConfig.getPartonNum());
        builder.setVisitPro(patronConfig.getVisitPro());
        return builder;
    }

    /**
     * 节奏表
     */
    public static JieShiProto.LightMarketRhythmConfig.Builder parseLightMarketRhythmConfig(LightMarketRhythmConfig rhythmConfig) {
        if (rhythmConfig == null) {
            return null;
        }
        JieShiProto.LightMarketRhythmConfig.Builder builder = JieShiProto.LightMarketRhythmConfig.newBuilder();
        builder.setRound(rhythmConfig.getRound());
        builder.setStandardForce(rhythmConfig.getStandardForce());
        builder.setStandardMoneySpeed(rhythmConfig.getStandardMoneySpeed());
        builder.setEventParam1(rhythmConfig.getEventParam1());
        builder.setEventParam2(rhythmConfig.getEventParam2());
        return builder;
    }

    /**
     * 事件表
     */
    public static JieShiProto.LightMarketEventConfig.Builder parseLightMarketEventConfig(LightMarketEventConfig eventConfig, String language) {
        if (eventConfig == null) {
            return null;
        }
        JieShiProto.LightMarketEventConfig.Builder builder = JieShiProto.LightMarketEventConfig.newBuilder();
        builder.setId(eventConfig.getId());
        builder.setType(eventConfig.getType());
        builder.setEventParam(eventConfig.getEventParam());
        builder.setEventText(ServerLanguageMgr.getContent(eventConfig.getEventText(), language));
        builder.setRewards(eventConfig.getRewards());
        builder.setWeight(eventConfig.getWeight());
        return builder;
    }

    public static List<JieShiMapBuildData> parseJieShiMapBuildData(List<JieShiProto.JieShiMapBuildDataTemp> tempList) {
        List<JieShiMapBuildData> list = new ArrayList<>();
        for (JieShiProto.JieShiMapBuildDataTemp temp : tempList) {
            JieShiMapBuildData data = new JieShiMapBuildData();
            data.setBuildId(temp.getBuildId());
            data.setPosition(temp.getPositionList());
            data.setDirection(temp.getDirection());
            list.add(data);
        }
        return list;
    }




}
